import logging

import allure
import pymysql
import requests

from config.config import DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD


def send_http_request(**request_data):
    with allure.step("发送http请求"):
        logging.info(f"发送http请求")
        res = requests.request(**request_data)
        return res

def send_sql_request(sql):
    connection = pymysql.Connection(
        host=DB_HOST,
        port=DB_PORT,
        database=DB_NAME,
        user=DB_USER ,
        password=DB_PASSWORD,
        charset="utf8",
        autocommit = True
    )

    cursor = connection.cursor()

    cursor.execute(sql)
    result = cursor.fetchone()
    cursor.close()
    connection.close()
    return result[0]